<?php

/**
 * 焦点图图片管理
 *
 * @package         YDCMS
 * @author          QQ:644157559 <644157559@qq.com>
 * @version         $Id: FocusImgModel.class.php v1.0 2014-06-23 17:27:03 $
 */
namespace Admin\Model;
class FocusImgModel extends CommonModel{
    /**
     * 一个图片对应一个焦点图
     * 自动关联Focus
     * @var type 
     */
    protected $_link = array(
        'Focus' => array(
            'mapping_type'  => self::BELONGS_TO,
            'class_name'    => 'Focus',
            'foreign_key'   => 'fid',
            'mapping_fields'=> 'title',
            'as_fields'     => 'title:focus_name'
        )
    );
    /**
     * 自动验证规则
     * @var type 
     */
    protected $_validate = array(
        array("fid", "require", "请选择所属焦点图！", 1),
        array("imgpath", "require", "请填写图片地址！", 1),
        array('lang', "checkLang", '语言选择有误！', 2, 'callback'), 
    );
    
    protected $_auto = array(
        array("create_time", "time", 1, "function"),
        array("sortrank", "intval", 3, "function"),
        array("status", "intval", 3, "function")
    );
    
    /**
     * 检查语言是否存在
     * @param type $lang
     * @return type
     */
    public function checkLang($lang) {
        return D("Language", "Service")->existLang($lang);
    }
}
